﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CodeC.Interfaces.UI;
using System.ComponentModel.Composition;
using Microsoft.Practices.Prism.Events;
using CodeC.Infrastructure.Events;
using CodeC.Interfaces;
using CodeC.Utilities;

namespace CodeC.UI.View
{
    /// <summary>
    /// Interaction logic for CodeCView.xaml
    /// </summary>
    [Export(typeof(ICodeCView))]
    public partial class CodeCView : UserControl, ICodeCView
    {
        [ImportingConstructor]
        public CodeCView(IEventAggregator eventAggregator)
        {
            InitializeComponent();

            eventAggregator.GetEvent<ErrorSelectionChangedEvent<IErrorModel>>().Subscribe(param => this.ErrorSelectionChanged(param));
            txtMain.Focus();
        }

        /// <summary>
        /// This method helps to highlight the Text Box text.
        /// </summary>
        /// <param name="param"></param>
        private void ErrorSelectionChanged(IErrorModel param)
        {
            switch (param.Section)
            {
                case "Main":
                    txtMain.HighlightLine(param.Line);
                    break;
                case "Class/Method":
                    txtClassMethods.HighlightLine(param.Line);
                    break;
                default:
                    break;
            }

        }

        public void SetView(Interfaces.UI.Base.IBaseViewModel viewModel)
        {
            this.DataContext = viewModel;
        }

    }
}
